<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="layout" content="main"/>
  <script type="text/javascript" src="${createLinkTo(dir: 'js/jquery', file: 'jquery-1.3.2.min.js')}"></script>
  <link rel="stylesheet" href="${createLinkTo(dir: 'facebox', file: 'facebox.css')}"/>
  <script type="text/javascript" src="${createLinkTo(dir: 'facebox', file: 'facebox.js')}"></script>
  
  <title>Plan List</title>
  <g:javascript>
    $(function() {
      $(".publish").click(function() {
          $(this).html('...');
          var it = this
          $.get($(this).attr('href'),{}, function(data) {
              if (data=="1") {
                 $(it).html('取消发布'); 
              } else if (data=="0") {
                  $(it).html('发布'); 
              } else {
                  alert("错误。");
                  $(it).html('发布');
              }
          });
          return false;
      });
      $('a[rel*=facebox]').facebox({
        loading_image : '${createLinkTo(dir: 'facebox', file: 'loading.gif')}',
        close_image   : '${createLinkTo(dir: 'facebox', file: 'closelabel.gif')}'
      });
        
    })
  </g:javascript>
</head>
<body>
<div class="nav">
  <span class="menuButton"><a class="home" href="${createLinkTo(dir: '')}">Home</a></span>
  <span class="menuButton"><g:link class="create" action="create">New Plan</g:link></span>
</div>
<div class="body">
  <h1>Plan List</h1>
  <g:if test="${flash.message}">
    <div class="message">${flash.message}</div>
  </g:if>
  <div class="list">
    <table>
      <thead>
      <tr>

        <g:sortableColumn property="id" title="Id"/>

        <g:sortableColumn property="name" title="Name"/>

        <g:sortableColumn property="description" title="Description"/>

        <g:sortableColumn property="planType" title="Plan Type"/>

        <g:sortableColumn property="startWith" title="Start With"/>

        <g:sortableColumn property="endWith" title="End With"/>

        <th>Action</th>

      </tr>
      </thead>
      <tbody>
      <g:each in="${planInstanceList}" status="i" var="planInstance">
        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">

          <td><g:link action="show" id="${planInstance.id}">${fieldValue(bean: planInstance, field: 'id')}</g:link></td>
          
          <td width="10%">${fieldValue(bean: planInstance, field: 'name')}</td>

          <td width="30%">${fieldValue(bean: planInstance, field: 'description')}</td>

          <td>${fieldValue(bean: planInstance, field: 'planType')}</td>

          <td>${fieldValue(bean: planInstance, field: 'startWith')}</td>

          <td>${fieldValue(bean: planInstance, field: 'endWith')}</td>
          <td><g:link action="edit" id="${planInstance.id}">编辑</g:link>|
              <g:link action="preview" id="${planInstance.id}" rel="facebox">预览</g:link>|
              <g:if test="${!planInstance.published}">
              <g:link action="ajaxpublish" id="${planInstance.id}" class="publish">发布</g:link>
              </g:if>
              <g:else><g:link action="ajaxpublish" id="${planInstance.id}" name="publish" class="publish">取消发布</g:link></g:else>
          </td>
        </tr>
      </g:each>
      </tbody>
    </table>
  </div>
  <div class="paginateButtons">
    <g:paginate total="${planInstanceTotal}"/>
  </div>
</div>
</body>
</html>
